/**
 * echart属性默认值
 * 结构跟官方配置手册一致，配合echart-util.js使用
 * _xxx（带下划线的前缀的属性）:
 *   用途1: 非echart原生属性，用于辅助计算echart属性
 *   用途2: 对应xxx属性的相关配置信息，如开关，单位，主题色等
 *          {
 *            switch: false,
 *            unit: 'px',
 *            light: '#999999',
 *            dark: '#a2b5c7',
 *            require: [
 *              'echart.xAxis.splitLine.lineStyle.color'
 *            ]
 *          }
 */

import CBA from '@/common/color_board_all.js';

// 线条样式
const lineStyle = {
  color: '#02E0E8',
  width: 1,
  type: 'solid',
  opacity: 1,
};

// xy轴公用属性
const xyAxis = {
  show: true,
  type: 'category',
  name: '',
  position: 'bottom',
  inverse: false,
  nameLocation: 'end',
  nameGap: 15,
  nameRotate: 0,
  min: 'dataMin',
  max: 'dataMax',
  splitNumber: 5,
  minInterval: 'auto',
  maxInterval: 'auto',
  interval: 'auto',
  nameTextStyle: {
    color: '',
    _color: CBA.xAxis.axisLabel.textStyle.color,
    fontSize: 12,
    fontWeight: 'normal',
    fontFamily: 'sans-serif',
  },
  axisLine: {
    show: true,
    symbol: ['none', 'none'],
    symbolSize: [0, 0],
    symbolOffset: [0, 0],
    onZero: false,
    lineStyle: {
      ...lineStyle,
      color: '',
      _color: CBA.xAxis.axisLine.lineStyle.color,
    },
  },
  axisTick: {
    show: true,
    alignWithLabel: false,
    interval: 'auto',
    inside: false,
    length: 5,
    lineStyle: {
      ...lineStyle,
    },
  },
  axisLabel: {
    show: true,
    margin: 8,
    rotate: 0,
    interval: 0,
    _interval: {
      switch: false,
    },
    inside: false,
    color: '',
    fontSize: 12,
    fontWeight: 'normal',
    fontFamily: 'sans-serif',
    showMinLabel: true,
    showMaxLabel: true,
    textStyle: {
      color: '',
      _color: CBA.xAxis.axisLabel.textStyle.color,
    },
  },
  splitLine: {
    show: true,
    _show: {
      require: ['echart.xAxis.splitLine.lineStyle.color', 'echart.yAxis.splitLine.lineStyle.color'],
    },
    interval: 'auto',
    lineStyle: {
      color: '',
      _color: CBA.yAxis.splitLine.lineStyle.color,
      width: 1,
      type: 'solid',
      opacity: 1,
    },
  },
};

const markLine = {
  symbol: ['none', 'none'],
  data: [
    {
      name: '',
      _serieName: '', // 分配给哪个系列
      _axisType: 'y', // 哪个轴的参考线
      _value: '', // 参考值
      _symbol: ['none', 'none'],
      label: {
        show: false,
        position: 'middle',
        formatter: '{b} {c}',
      },
      lineStyle: {
        ...lineStyle,
        type: 'dashed',
        _color: CBA.markLine.lineStyle.color,
      },
    },
  ],
};

const markArea = {
  data: [
    [
      {
        xAxis: null,
        yAxis: null,
        name: '', // 名称
        _serieName: '', // 分配给哪个系列
        label: {
          show: false,
          position: 'top',
          color: '#26B0FF',
        },
        emphasis: {
          label: {
            position: 'top',
          },
        },
        itemStyle: {
          color: 'rgba(38, 176, 255, 0.3)',
          opacity: 1,
        },
      },
      {
        xAxis: null,
        yAxis: null,
      },
    ],
  ],
};

// series共用属性
const series = {
  label: {
    show: true,
    position: 'top',
    offset: [0, 0],
    rotate: 0,
    color: '',
    fontSize: 12,
    fontWeight: 'normal',
    fontFamily: 'sans-serif',
    _forType: 'all', // 限定类型： all, all_bar, all_pie, ..., serie_name
    _serieName: '', // 当选定forType=serie_name时，指定应用在哪个系列上
    _unit: '', // 单位
    _format: '', // 自定义格式
  },
};

const gridPadding = {
  top: 30,
  bottom: 50,
  left: 40,
  right: 50,
};

// ==========================================

export default {
  echart: {
    backgroundColor: '',
    _backgroundColor: CBA.backgroundColor,
    legend: {
      type: 'scroll',
      show: true,
      icon: 'circle',
      left: 'auto',
      top: 'auto',
      right: 'auto',
      bottom: 'auto',
      width: 'auto',
      height: 'auto',
      orient: 'horizontal',
      align: 'left',
      itemGap: 10,
      textStyle: {
        color: '',
        _color: CBA.legend.textStyle.color,
        fontSize: 12,
        fontWeight: 'normal',
        fontFamily: 'sans-serif',
      },
    },
    _legends: [],
    grid: {
      show: false,
      ...gridPadding,
    },
    xAxis: {
      ...xyAxis,
      position: 'bottom',
      splitLine: {
        ...xyAxis.splitLine,
        show: false,
      },
    },
    yAxis: {
      ...xyAxis,
      type: 'value',
      position: 'left',
    },
    splitLine: {
      ...xyAxis.splitLine,
      show: [false, true],
    },
    dataZoom: {
      inside: {
        type: 'inside',
        disabled: false,
        start: 0,
        end: 100,
        startValue: null,
        endValue: null,
        orient: 'horizontal',
        zoomLock: false,
        _zoomUnLock: true, // 跟zoomLock相反
        zoomOnMouseWheel: true,
        moveOnMouseMove: true,
        filterMode: 'none', // 解决单轴折线图放大报错
      },
      slider: {
        type: 'slider',
        show: false,
        showDetail: false,
        showDataShadow: false,
        _barNum: 6, // 非echart原生属性，用于显示多少组
        start: 0,
        end: 30,
        startValue: null,
        endValue: null,
        orient: 'horizontal',
        zoomLock: true,
        _zoomUnLock: false, // 跟zoomLock相反
        top: 'auto',
        bottom: 0,
        left: 'auto',
        right: 'auto',
        height: 4,
        handleSize: 0,
        moveHandleSize: 0,
        borderColor: 'transparent',
        backgroundColor: '',
        _backgroundColor: CBA.dataZoom.backgroundColor,
        fillerColor: '',
        _fillerColor: CBA.dataZoom.fillerColor,
        minValueSpan: 1, // 颗粒度
        filterMode: 'none', // 解决单轴折线图放大报错
      },
    },
    series: {

      // ======== 公共属性设置
      ...series,
      markLine,
      markArea,
      _labels: [
        // 存储所有数据标签
        series.label,
      ],

      // ======== 图表类型特定设置
      line: {
        ...series,
        markLine,
        markArea,
        lineStyle: {
          ...lineStyle,
          width: 2,
        },
        smooth: true,
      },
      bar: {
        ...series,
        barWidth: 'auto',
        barGap: 'auto', // 设-100%则可重叠
        _barGap: {
          unit: '%',
        },
        stack: '', // 设同一值则可堆叠
        _stackName: 'parallel', // "parallel"|"stack"
        showBackground: false,
        backgroundStyle: {
          color: '',
        },
        itemStyle: {
          color: '',
          borderColor: '',
          borderWidth: 0,
          borderType: 'solid',
          borderRadius: 0,
        },
      },
      pie: {
        ...series,
        selectedMode: false,
        selectedOffset: 10,
        clockwise: true,
        startAngle: 90,
        minAngle: 0,
        minShowLabelAngle: 0,
        roseType: false,
        cursor: 'pointer',
        left: 0,
        top: 0,
        right: 0,
        bottom: 0,
        width: 'auto',
        height: 'auto',
        radius: [35, 50],
        '_radius_0': { unit: '%' },
        '_radius_1': { unit: '%' },
        center: [25, 50],
        '_center_0': { unit: '%' },
        '_center_1': { unit: '%' },
        label: {
          show: false,
          position: 'outside',
          rotate: null,
          color: '',
          fontSize: 12,
          fontFamily: 'sans-serif',
          fontWeight: 'normal',
          overflow: 'none',
          alignTo: 'none',
          _unit: '', // 单位
        },
        labelLine: {
          show: true,
          length: 0,
          length2: 10,
          smooth: false,
        },
        emphasis: {
          scale: true,
          scaleSize: 10,
        },
      },
      sankey: {
        ...gridPadding,
        right: 60,
        orient: 'horizontal',
        width: 50,
        _width: {
          unit: '%',
        },
        nodeWidth: 20,
        nodeGap: 8,
        draggable: true,
        nodeAlign: 'left',
        label: {
          show: true,
          position: 'right',
          rotate: 0,
          color: '',
          _color: CBA.label.title.color,
          fontSize: 12,
          fontWeight: 'normal',
          fontFamily: 'sans-serif',
          align: 'left',
          verticalAlign: 'top',
        },
        itemStyle: {
          opacity: 1,
        },
      },
      tree: {
        ...gridPadding,
        label: {
          show: true,
          position: 'top',
          fontWeight: 'normal',
          fontFamily: 'sans-serif',
        },
        lineStyle: {
          color: '',
          _color: {
            light: '#D9E0E6',
            dark: '#02E0E8',
          },
          width: 1,
          type: 'solid',
        },
      },
      treemap: {
        top: 10,
        bottom: 20,
        left: 20,
        right: 20,
      },
      radar: {
        ...gridPadding,
        ...series,
      },
    },

    // 图行设置按图例名
    _nameSeries: [{ name: '', type: '', legendIcon: '' }],

    // 图形设置按左右轴
    _yzSeries: [{ name: '', type: '', legendIcon: '' }],

    // 同步操作，如缩放，图例点击
    _sharedActions: [{ key: '', type: '' }],

    // 转置xy轴
    _tranXYAxis: false,
  },
};
